from django.contrib import admin

from .models import Category, Item, Cart, Order, OrderItem


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ('id', 'name')
    list_display_links = ('id', 'name')
    search_fields = ('name',)


@admin.register(Item)
class ItemAdmin(admin.ModelAdmin):
    list_display = (
        'id',
        'category',
        'name',
        'description',
        'price',
        'image',
        'is_sold',
        'created_by',
        'created_at',
    )
    list_display_links = ('id', 'name')
    list_filter = ('category', 'is_sold', 'created_by', 'created_at')
    search_fields = ('name',)
    date_hierarchy = 'created_at'


@admin.register(Cart)
class CartAdmin(admin.ModelAdmin):
    list_display = ('id', 'user', 'item', 'quantity', 'is_order', 'created_at')
    list_display_links = ('id', 'item')
    list_filter = ('user', 'item', 'created_at')
    date_hierarchy = 'created_at'


@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_display = (
        'id',
        'user',
        'is_paid',
        'name',
        'email',
        'address',
        'postal_code',
        'city',
        'created_at',
        'modified_at',
    )
    list_display_links = ('id', 'user')
    list_filter = ('created_at', 'modified_at', 'is_paid')
    search_fields = ('name',)
    date_hierarchy = 'created_at'


@admin.register(OrderItem)
class OrderItemAdmin(admin.ModelAdmin):
    list_display = ('id', 'order', 'cart')
    list_filter = ('order', 'cart')
